package com.cloud.user.controller;

import com.cloud.common.entity.po.Result;
import com.cloud.user.bo.UserBO;
import com.cloud.user.entity.UserDO;
import com.cloud.user.service.UserService;
import jakarta.annotation.Resource;
import lombok.extern.log4j.Log4j2;
import org.apache.catalina.User;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Log4j2
@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    private UserService userService;

    @PostMapping("/login")
    Result<String> login(@RequestBody User user) {
        /* TODO 用户登录操作 */
        return Result.success("登录接口返回数据");
    }

    @GetMapping("/test")
    Result<String> test() {
        return Result.success("openfeign远程调用test");
    }

      /**
       * @description: 测试远程调用数据库查询数据
       * @author wuyue
       * @date 2025/2/16 13:35
       * @version 1.0
       */
    @GetMapping("/testCloud")
    public  Result testCloud(@RequestParam("userName") String userName) {
        try {
               // 测试Hystrix的熔断效果
            try {
                Thread.sleep(30000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            UserDO userDO = userService.getOne(userName);
           return   Result.success(userDO);
        } catch (Exception e) {
            log.error("查询异常", e);
            return Result.error(e.getMessage());
        }
    }
}
